#include "Assert.h"

#include "Containers/String8.h"
#include <iostream>
#include "Output/Console.h"

#ifdef WIN32
    #include <string>
    #include <format>
    #include <Windows.h>
#else
    #include <cassert>

#endif

#ifdef DEBUG
void WH::AssertFailed(
    const char8_t * InExpression
    , const CString & InMessage
    , const char8_t * InFile, int InLine
    , const char8_t * InFunction)
{
    //输出utf8格式的字符串
    CString Output=U"Assertion failed: ";
    Output+=InExpression;
    Output+=U" ";
    Output+=InMessage;
    Output+=U" ";
    Output+=InFile;
    Output+=U" ";
    Output+=CString(InLine);
    Output+=U" ";
    Output+=InFunction;

    //使用输出而不是错误输出
    //因为输出可以通过socket发送到编辑器调试器
    WH::PrintLine(Output);

    //触发系统断言，在Windows下会弹出对话框
#ifdef WIN32
    auto Output16=Output.ToUtf16();
    CString File=InFile;
    auto File16=File.ToUtf16();

    _wassert(
        (const wchar_t*)Output16.Data(),
        (const wchar_t*)File16.Data(),
        InLine);
#else
    assert(false); 
#endif
}
#endif